﻿using nanhua.BookStore.Entitys.OrderAggregate;
using nanhua.BookStore.Entitys.ProductAggregate;
using nanhua.BookStore.Entitys.ProductCategoryAggregate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Uow;

namespace nanhua.BookStore.Orders
{
    /// <summary>
    /// 产品类型领域种子数据初始化
    /// </summary>
    public class ProductDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        IProductRepository _productRepository;
        IGuidGenerator _guidGenerator;
        public ProductDataSeedContributor(IProductRepository productRepository, IGuidGenerator guidGenerator)
        {
            this._productRepository = productRepository;
            this._guidGenerator = guidGenerator;
        }
        [UnitOfWork]
        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _productRepository.GetCountAsync() <= 0)
            {
                var product = new Product(_guidGenerator.Create(),"P_A001", 45, "华为P40手机");
                var product1 = new Product(_guidGenerator.Create(),"P_A002", 45, "红米手机");
                await _productRepository.InsertAsync(product);
                await _productRepository.InsertAsync(product1);
            }
        }
    }
}
